﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FizzBuzzCore;
using FizzBuzzCore.Interfaces;

namespace FizzBuzzConsole
{
    /// <summary>
    /// Prints the FizzBuzz sequence from 1 to 100
    /// </summary>
    class Program
    {
        private static IFizzBuzz fizzBuzz;

        /// <summary>
        /// Calls and executes the FizzBuzz class
        /// </summary>
        /// <param name="args">Command line arguments</param>
        static void Main(string[] args)
        {
            try
            {
                fizzBuzz = FizzBuzz.NewObject();
                fizzBuzz.LowerLimit = 1;
                fizzBuzz.UpperLimit = 100;
                PrintToConsole();
                DisplayAnyKeyMessage();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                DisplayAnyKeyMessage();
            }
        }

        /// <summary>
        /// Prints to the console
        /// </summary>
        private static void PrintToConsole()
        {
            if (fizzBuzz != null)
            {
                foreach (string item in fizzBuzz.FizzBuzzList)
                {
                    Console.WriteLine(item);
                }
            }
            else
            {
                throw new NullReferenceException(FizzBuzzConsoleResource.fizzBuzzNullReferenceExceptionText);
            }
        }

        /// <summary>
        /// Prints 'Press Any Key To Continue' to the console
        /// </summary>
        private static void DisplayAnyKeyMessage()
        {
            Console.WriteLine(FizzBuzzConsoleResource.pressAnyKeyMessage);
            Console.ReadKey();
        }
    }
}
